package request

import (
	"sync"

	"gddgame.cc/galaxy/utils/def"
)

type Pool struct {
	def.Logger
	pool sync.Pool
}

func NewPool(logger def.Logger) *Pool {
	p := &Pool{
		Logger: logger,
		pool:   sync.Pool{},
	}
	p.pool.New = func() interface{} {
		return New()
	}
	return p
}

func (pool *Pool) New() *SuperAgent {
	agent := pool.pool.Get().(*SuperAgent)
	agent.SetLogger(pool)
	return agent
}

func (pool *Pool) Release(agent *SuperAgent) {
	agent.ClearSuperAgent()
	pool.pool.Put(agent)
}
